import java.util.ArrayList;

public class MethodDecls
{
	private ArrayList<MethodDecl> methods;
	
	public MethodDecls()
	{
		methods = new ArrayList<MethodDecl>();
	}
	
	
	public void addMethodDecl(MethodDecl md)
	{
		methods.add(md);
	}
	
	public String toString()
	{
		String ret = "";
		if(methods.size()>0)
		{
			ret+="MethodsDecl \n";
		}
		
		for(MethodDecl md : methods)
		{
			ret+= md.toString();
		}
		
		return ret;
	}
	
	public void check() throws SemanticException{
				
		SymbolTable st = SymbolTable.getInstance();
		
		for(MethodDecl md : methods){
			
			if(st.contains(md.methodName))
			{
				String details = "The identifier "+md.methodName+" already exists.";
				if( md.dataInfo != null )
					throw new SemanticException( md.dataInfo.lineNumber, md.dataInfo.charNumber, md.dataInfo.line, details );
				else
					throw new SemanticException( details );
			}
			
			st.add(new Entry(md.methodName, "Method", md.methodType));
			
		}
		
		for(MethodDecl md: methods)
			md.check();
		
	}
}